/**
 * config.js v1.0.0 by @businka and @kreedev
 * Copyright 2013 Koltsovs Inc.
 **/

var Config = {
    Ids: {
        Legend: "Legend"
    },
    Names: {
        Ru: {
            App: "Калькулятор"
        },
        En: {
            App: "Calculator"
        }
    },
    SetTitle: function (lang) {
        Logger.Info("Config.SetTitle: " + lang);

        document.title = this.Names[lang].App;
    },
    SetLegend: function (lang) {
        Logger.Info("Config.SetLegend: " + lang);

        var legend = document.getElementById(this.Ids.Legend);
        legend.innerHTML = this.Names[lang].App;
    },
    Init: function () {
        var self = this;
        Logger.SetLogLevel(Defaults.LogLevel);

        Logger.Info("Config.Init");

        self.SetColor(Defaults.Color);
        self.UpdateColor();

        self.SetBackgroundColor(Defaults.BackgroundColor);
        self.UpdateBackground();

        self.SetLanguage(Defaults.Language);
        self.UpdateLanguage();

        Calculator.Init();

        if (Defaults.AutoStart === true) {
            self.PlayAudio(Defaults.Song, Defaults.LoopSong);
        }
    },
    SetLanguage: function (language) {
        Logger.Info("Config.SetLanguage: " + language);

        this.Language = language;
    },
    UpdateLanguage: function () {
        Logger.Info("Config.UpdateLanguage");

        var language = this.Language;
        this.SetTitle(language);
        this.SetLegend(language);
    },
    SetColor: function (color) {
        Logger.Info("Config.SetColor: " + color);

        this.Color = color;
    },
    SetBackgroundColor: function (color) {
        Logger.Info("Config.SetBackgroundColor: " + color);

        this.BackgroundColor = color;
    },
    UpdateColor: function () {
        Logger.Info("Config.UpdateColor");
        var color = this.Color;

        $("#divCalculator").css("color", color);
        $("#divCalculator").css("border-color", color);
        $("#fieldsetCalculator").css("border-color", color);
        $("#Input").css("color", color);
        $('input[type="button"]').css("color", color);
        $('input[type="button"]').css("border-color", color);
        $("#Input").css("border-color", color);
    },
    UpdateBackground: function () {
        Logger.Info("Config.UpdateBackground");
        var color = this.BackgroundColor;

        $('input[type="button"]').css("background-color", color);
        $("#Input").css("background-color", color);
        $('#divMain').css("background-color", color);
    },
    PlayAudio: function (song, loop) {
        Logger.Info("Config.PlayAudio: " + song);

        var audio = document.createElement("audio");
        audio.loop = loop;
        audio.setAttribute("src", song);
        audio.play();
    }
};

Config.Init();